import { createPinia } from 'pinia'

import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

import type { App } from 'vue'

function setupPinia(app: App<Element>) {

    const pinia = createPinia()

    pinia.use(piniaPluginPersistedstate)
    pinia.use(({ store }) => {
      const initialState = JSON.parse(JSON.stringify(store.$state))
      store.$reset = () => {
        store.$state = JSON.parse(JSON.stringify(initialState))
      }
    })
    
    app.use(pinia)

}

export {
    setupPinia
}